package com.ymttest.database.sqlwapper;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.ymatou.iapi.trading.operate.parameter.po.SubcatalogsPo;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.utils.MapUtil;

/************************************************************************************
 * @File name : YmtProductsIWapper.java
 * @Author : 徐洁伟
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class YmtProductsIWapper {
	SqlManager manage;

	public YmtProductsIWapper() {
		manage = new SqlManager("intpro");
	}

	//查询
	public List<YmtProductsI> selectProductByProductId(String sProductId)
			throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<YmtProductsI> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.selectProductByProductId",
						sProductId);
		manage.commit();
		return sProductIdlist;
	}

	//查询
	public List<Map> selectProductByProductIdforMap(String sProductId)
			throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.selectProductByProductIdforMap",
						sProductId);
		//	    manage.commit();
		return sProductIdlist;
	}

	//更新
	public int updateValidtimeByProductId(Date dvalidStart, Date dvalidEnd,
			String sProductId) throws InterruptedException {
		Map m = new HashMap();
		m.put("dvalidStart", dvalidStart);
		m.put("dvalidEnd", dvalidEnd);
		m.put("sProductId", sProductId);
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateValidtimeByProductId",
						m);
		manage.commit();
		// manage.close();
		return i;
	}

	public int updateCatalogTypeByProductId(String productId, int catalogType) {
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateCatalogTypeByProductId",
						MapUtil.hashMap("sProductId", productId,
								"iCatalogType", catalogType));
		manage.commit();
		return i;
	}

	//更新YMT_SellerLoginLimitAutoOnShevel
	public int updateSellerLoginByUserId(Date dStartTime, Date dEndTime,
			int userId) throws InterruptedException {
		Map m = new HashMap();
		m.put("dStartTime", dStartTime);
		m.put("dEndTime", dEndTime);
		m.put("userId", userId);
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateSellerLoginByUserId",
						m);
		manage.commit();
		// manage.close();
		return i;
	}

	public int updateIsNewByUserId(int sellerId, boolean isNew) {
		Map m = new HashMap();
		m.put("iUserId", sellerId);
		m.put("isNew", isNew);
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateIsNewByUserId",
						m);
		manage.commit();
		// manage.close();
		return i;
	}

	
	public int updateCheckStatus(String productId, int checkStatus) {
		Map m = new HashMap();
		m.put("ProductId", productId);
		m.put("CheckStatus", checkStatus);
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateCheckStatus",
						m);
		manage.commit();
		// manage.close();
		return i;
	}
	
	
	public int updateCategoryId(String productId, int categoryId) {
		Map m = new HashMap();
		m.put("ProductId", productId);
		m.put("CategoryId", categoryId);
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateCategoryId",
						m);
		manage.commit();
		// manage.close();
		return i;
	}
	
	
	
	
	public int updateCatalogStatus(String productId, int catalogStatus) {
		Map m = new HashMap();
		m.put("ProductId", productId);
		m.put("CatalogStatus", catalogStatus);
		int i = manage
				.update("com.ymttest.database.mapping.YmtProductsIMapper.updateCatalogStatus",
						m);
		manage.commit();
		// manage.close();
		return i;
	}
	
	
	//查询
	public List<Map> selectSubscribeRecord(int iUserId, String sSKU)
			throws InterruptedException {
		@SuppressWarnings("unchecked")
		Map m = new HashMap();
		m.put("iUserId", iUserId);
		m.put("sSKU", sSKU);
		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.selectSubscribeRecord",
						m);
		//	    manage.commit();
		return sProductIdlist;
	}

	//查询商品描述
	public List<Map> selectDescConfigByProductId(String sProductId)
			throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.selectDescConfigByProductId",
						sProductId);
		//	    manage.commit();
		return sProductIdlist;
	}

	public List<Map> selectDescPicConfigByProductId(String sProductId)
			throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.selectDescPicConfigByProductId",
						sProductId);
		//	    manage.commit();
		return sProductIdlist;
	}

	public List<Map> getSellerProductDetailList(String productId, int sellerId,
			int curPage, int pageSize) throws InterruptedException {

		Map m = new HashMap();
		m.put("productId", productId);
		m.put("sellerId", sellerId);
		m.put("curPage", curPage);
		m.put("pageSize", pageSize);

		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getSellerProductDetailList",
						m);
		//	    manage.commit();
		return sProductIdlist;
	}

	public List<Map> getSellerProductDetailList_product(String productId)
			throws InterruptedException {

		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getSellerProductDetailList_product",
						productId);
		return sProductIdlist;
	}

	public List<Map> getSellerProductDetailList_Catalogs(String productId,
			Integer sellerId) throws InterruptedException {
		Map m = new HashMap();
		m.put("productId", productId);
		m.put("sellerId", sellerId);

		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getSellerProductDetailList_Catalogs",
						m);
		return sProductIdlist;
	}

	public List<Map> getSellerProductDetailList_CatalogProperty(String productId)
			throws InterruptedException {

		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getSellerProductDetailList_CatalogProperty",
						productId);
		return sProductIdlist;
	}

	public List<Map> getSellerProductDetailList_ProductPicture(String productId)
			throws InterruptedException {

		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getSellerProductDetailList_ProductPicture",
						productId);
		return sProductIdlist;
	}

	public List<Map> getProductDeliveryTemplateByProdId(String productId)
			throws InterruptedException {

		List<Map> sProductIdlist = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getProductDeliveryTemplateByProdId",
						productId);
		return sProductIdlist;
	}

	/**
	 * ymt_subcatalogs 随机返回前100条中的一条组合商品
	 * @return
	 * @throws InterruptedException
	 */
	public SubcatalogsPo getSubcatalogs() throws InterruptedException {

		List<SubcatalogsPo> subcatalogsPoList = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtProductsIMapper.getSubcatalogs",
						null);

		return subcatalogsPoList.get(new Random().nextInt(subcatalogsPoList
				.size() - 1));

	}
	public static void main(String args[]) throws Exception {

		List<Map> aa = new YmtProductsIWapper().selectProductByProductIdforMap("3fe91640-5376-420f-a04c-07ceb50d801a");
		new YmtProductsIWapper().updateCheckStatus("1682aae1-6677-41bd-9936-aea5eff3ac09", -1)	;
		int c = 1;
		int aaa = c;

		/*        List<Map> rm = ymtProductsIWapper.selectSubscribeRecord(3383,"FBXSKU7072");
		        Logger.debug(rm.get(0));*/
		//	    	Date startTime = (new SimpleDateFormat("yyyy-MM-dd")).parse(YMTDateUtil.getBeforeOrNextDay(-1));
		//			Date endTime = (new SimpleDateFormat("yyyy-MM-dd")).parse(YMTDateUtil.getBeforeOrNextDay(-1));
		//	    	int ret = ymtProductsIWapper.updateSellerLoginByUserId(startTime,endTime,20336378);
		//	        Logger.debug(ret);

	}

}
